#include "Display.h"
void BMPInfoHeadInit(BITMAPINFO *bi, WORD width,WORD height, WORD bitCount)
{
	if(NULL == bi)	return;
	bi->bmiHeader.biSize				=   sizeof(BITMAPINFOHEADER); 
	bi->bmiHeader.biWidth				=   width;   
	bi->bmiHeader.biHeight			=   height;   
	bi->bmiHeader.biPlanes			=   1;   
	bi->bmiHeader.biBitCount			=   bitCount; 
	bi->bmiHeader.biCompression		=   BI_RGB;   
	bi->bmiHeader.biSizeImage			=   0;   
	bi->bmiHeader.biXPelsPerMeter  	=   1;   
	bi->bmiHeader.biYPelsPerMeter  	=   1;   
	bi->bmiHeader.biClrUsed			=   0;   
	bi->bmiHeader.biClrImportant		=   0;   
	if(8 == bitCount)
	{
		for(int   i   =   0;   i   <   256;   ++i) 
		{  
			bi->bmiColors[i].rgbBlue	=   i; 
			bi->bmiColors[i].rgbGreen   =   i; 
			bi->bmiColors[i].rgbRed		=   i; 
			bi->bmiColors[i].rgbReserved     =   0; 
		}
	}
}

void StretchOnRect(HDC hDC, RECT &destRt, WORD width, WORD height, WORD bpp, void * pImage)
{
	if( NULL == pImage)		return;
	int LUTSize = 0;
	const	int colorSort = 0x01<<8;
	char     __bif[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * colorSort]; 
	BITMAPINFO&   bif				=   *(BITMAPINFO*)__bif;
	BMPInfoHeadInit(&bif, width, height, bpp);	   
	
	SetStretchBltMode(hDC, COLORONCOLOR);
	StretchDIBits(hDC,   destRt.left,   destRt.top,   destRt.right - destRt.left, destRt.bottom - destRt.top,   
			  0,0,width,height,pImage,(BITMAPINFO*)&bif,   DIB_RGB_COLORS,   SRCCOPY);
}

void CopyOnRect(HDC hDC, RECT &destRt, WORD width, WORD height, WORD bpp, void * pImage)
{
	int LUTSize = 0;
	const	int colorSort = 0x01<<8;
	char     __bif[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * colorSort]; 
	BITMAPINFO&   bif				=   *(BITMAPINFO*)__bif; 
	BMPInfoHeadInit(&bif, width, height, bpp);
	
//	SetStretchBltMode(hDC, COLORONCOLOR);
//	StretchDIBits(hDC,   destRt.left,   destRt.top,   destRt.right - destRt.left, destRt.bottom - destRt.top,   
//			  0,0,width,height,pImage,(BITMAPINFO*)&bif,   DIB_RGB_COLORS,   SRCCOPY);
	SetDIBitsToDevice	(	hDC, destRt.left, destRt.top, destRt.right - destRt.left, destRt.bottom - destRt.top,
						0, 0, 0, destRt.bottom - destRt.top, pImage, (BITMAPINFO *)&bif, DIB_RGB_COLORS);
}
